<?php

class LottoAction extends CommonAction {
	private $prize_type = 'lotto';
	
	
	
	
	
	
	public function _getAll(){
			$join = ' ws_prize_store on ws_prize_store.prst_id=ws_prize_lotto.prst_id ';
			$list = M('PrizeLotto')->join($join)->select();
		return $list;
	}
	
	public function _getAllForIndex(){
		if(!S('lotto_prize')){
			$list = $this->_getAll();
			$list[] = $this->_item();
			shuffle($list);
			$lotto[1] = array($list[0], $list[1], $list[2], $list[3], $list[4]);
			$lotto[2] = array($list[5], $list[6], $list[7]);
			$lotto[3] = array($list[8], $list[9], $list[10]);
			$lotto[4] = array($list[11], $list[12], $list[13], $list[14], $list[15]);
			$lotto = $this->setLocation($lotto);
			S('lotto_prize', $lotto);
		}else{
			$lotto = S('lotto_prize');
		}
		return $lotto;
	}
	
	# 初始化一个未中奖的选项
	private function _item(){
		$item = array(
				"lo_id" => "0",
				"lo_name" => "未中奖",
				"prst_id" => "0",
				"prst_num" => "0",
				"lo_count" => "0",
				"lo_probability" => "0",
				"lo_pic" => "sky/images/cj_11.png",
				"prst_name" => "未中奖",
				"prst_pic" => "sky/images/pic.png",
		);
		return $item;
	}
	
	private function setLocation($lotto){
		$lotto[1][0]['location'] = 1;
		$lotto[1][1]['location'] = 2;
		$lotto[1][2]['location'] = 3;
		$lotto[1][3]['location'] = 4;
		$lotto[1][4]['location'] = 5;
		
		$lotto[2][0]['location'] = 16;
		$lotto[2][1]['location'] = 15;
		$lotto[2][2]['location'] = 14;
		
		$lotto[3][0]['location'] = 6;
		$lotto[3][1]['location'] = 7;
		$lotto[3][2]['location'] = 8;
		
		$lotto[4][0]['location'] = 13;
		$lotto[4][1]['location'] = 12;
		$lotto[4][2]['location'] = 11;
		$lotto[4][3]['location'] = 10;
		$lotto[4][4]['location'] = 9;
		return $lotto;
	}
	
	
	public function onLotto(){
		$params['userinfo'] = $this->Core->User;
		B('Lotto', $params);
	}
	
	
	
	

}
?>